package com.sinux.sshUser.common.interceptor;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.sinux.sshUser.entity.User;

/**
 * @author WangGan
 * @version 2017年5月23日 下午10:56:38 
 * 拦截器
 * 
 */
public class UserInterceptor implements HandlerInterceptor{
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		//获取Session 如果为空拦截
        User user = (User) request.getSession().getAttribute("sshUser");
        //判断是否为空
        if (user != null) {
            return true;
        }
        response.sendRedirect(request.getContextPath()+"/admin/login");
        return false;
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub

	}
}
